using DevExpress.Utils;
using Common.Base;
using System;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
namespace Common.Class
{
	public class Options
	{
		public class Regional
		{
			private static bool _mIsQuestion = true;
			private static string _mDecimalSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
			private static bool _mIsMsgBoxResult = true;
			private static string _mDigitGroupSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
			private static int _mDecimals = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits;
			private static string _mDateSaparator = CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator;
			private static string _mFormatDate = "dd/MM/yyyy";
			private static Options.FormatType _mDateFormatType = Options.FormatType.Custom;
			private static string _mFormatNumber = "##,##0.###";
			private static int _mNumberDecimalDigits = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits;
			public static string FormatNumber
			{
				get
				{
					string text = "##,##0.";
					for (int i = 0; i < Options.Regional._mDecimals; i++)
					{
						text += "#";
					}
					Options.Regional._mFormatNumber = text;
					return text;
				}
				set
				{
					Options.Regional._mFormatNumber = value;
				}
			}
			public static string StringFormat
			{
				get
				{
					return "{0:" + Options.Regional.FormatNumber + "}";
				}
			}
			public static Options.FormatType DateFormatType
			{
				get
				{
					return Options.Regional._mDateFormatType;
				}
				set
				{
					Options.Regional._mDateFormatType = value;
				}
			}
			public static string FormatDate
			{
				get
				{
					string mFormatDate;
					switch (Options.Regional._mDateFormatType)
					{
					case Options.FormatType.Dmy:
						Options.Regional._mFormatDate = Options.FormatType.Dmy.ToString().Replace("/", Options.Regional._mDateSaparator);
						mFormatDate = Options.Regional._mFormatDate;
						break;
					case Options.FormatType.Mdy:
						Options.Regional._mFormatDate = Options.FormatType.Mdy.ToString().Replace("/", Options.Regional._mDateSaparator);
						mFormatDate = Options.Regional._mFormatDate;
						break;
					case Options.FormatType.Ymd:
						Options.Regional._mFormatDate = Options.FormatType.Ymd.ToString().Replace("/", Options.Regional._mDateSaparator);
						mFormatDate = Options.Regional._mFormatDate;
						break;
					default:
						mFormatDate = Options.Regional._mFormatDate;
						break;
					}
					return mFormatDate;
				}
				set
				{
					Options.Regional._mDateFormatType = Options.FormatType.Custom;
					Options.Regional._mFormatDate = value;
				}
			}
			public static string DateSaparator
			{
				get
				{
					return Options.Regional._mDateSaparator;
				}
				set
				{
					Options.Regional._mDateSaparator = value;
				}
			}
			public static int Decimals
			{
				get
				{
					return Options.Regional._mDecimals;
				}
				set
				{
					Options.Regional._mDecimals = value;
				}
			}
			public static string DigitGroupSymbol
			{
				get
				{
					return Options.Regional._mDigitGroupSymbol;
				}
				set
				{
					Options.Regional._mDigitGroupSymbol = value;
				}
			}
			public static string DecimalSymbol
			{
				get
				{
					return Options.Regional._mDecimalSymbol;
				}
				set
				{
					Options.Regional._mDecimalSymbol = value;
				}
			}
			public static bool IsQuestion
			{
				get
				{
					return Options.Regional._mIsQuestion;
				}
				set
				{
					Options.Regional._mIsQuestion = value;
				}
			}
			public static bool IsMsgBoxResult
			{
				get
				{
					return Options.Regional._mIsMsgBoxResult;
				}
				set
				{
					Options.Regional._mIsMsgBoxResult = value;
				}
			}
			public static int NumberDecimalDigits
			{
				get
				{
					return Options.Regional._mNumberDecimalDigits;
				}
				set
				{
					Options.Regional._mNumberDecimalDigits = value;
				}
			}
		}
		public enum FormatType
		{
			Dmy = 1,
			Mdy,
			Ymd,
			Custom = 0
		}
		public class Number
		{
			private static string _mDecimalSymbol = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;
			private static string _mDigitGroupSymbol = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator;
			private static int _mDecimals = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalDigits;
			private static string _mFrefixSymbol = "";
			private static string _mSuffixSymbol = "";
			private static string _mFormatNumber = "##,##0.###";
			private static bool _mAutoRound = true;
			public static string Format
			{
				get
				{
					string text = "##,##0.";
					for (int i = 0; i < Options.Number._mDecimals; i++)
					{
						text += (Options.Number._mAutoRound ? "#" : "0");
					}
					Options.Number._mFormatNumber = Options.Number._mFrefixSymbol + text + Options.Number._mSuffixSymbol;
					return Options.Number._mFormatNumber;
				}
				set
				{
					Options.Number._mFormatNumber = value;
				}
			}
			public static string FormatString
			{
				get
				{
					return "{0:" + Options.Number.Format + "}";
				}
			}
			public static int Decimals
			{
				get
				{
					return Options.Number._mDecimals;
				}
				set
				{
					Options.Number._mDecimals = value;
				}
			}
			public static string DigitGroupSymbol
			{
				get
				{
					return Options.Number._mDigitGroupSymbol;
				}
				set
				{
					Options.Number._mDigitGroupSymbol = value;
				}
			}
			public static string DecimalSymbol
			{
				get
				{
					return Options.Number._mDecimalSymbol;
				}
				set
				{
					Options.Number._mDecimalSymbol = value;
				}
			}
			public static string FrefixSymbol
			{
				get
				{
					return Options.Number._mFrefixSymbol;
				}
				set
				{
					Options.Number._mFrefixSymbol = value;
				}
			}
			public static string SuffixSymbol
			{
				get
				{
					return Options.Number._mSuffixSymbol;
				}
				set
				{
					Options.Number._mSuffixSymbol = value;
				}
			}
			public static bool AutoRound
			{
				get
				{
					return Options.Number._mAutoRound;
				}
				set
				{
					Options.Number._mAutoRound = value;
				}
			}
		}
		public class DateTime
		{
			private static string _mDateSaparator = CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator;
			private static string _mFormatDate = "dd/MM/yyyy";
			private static int _mDayLength = 2;
			private static int _mMonthLength = 2;
			private static int _mYearLength = 4;
			private static Options.FormatType _mDateFormatType = Options.FormatType.Custom;
			public static Options.FormatType FormatType
			{
				get
				{
					return Options.DateTime._mDateFormatType;
				}
				set
				{
					Options.DateTime._mDateFormatType = value;
				}
			}
			public static string Format
			{
				get
				{
					string mFormatDate;
					switch (Options.DateTime._mDateFormatType)
					{
					case Options.FormatType.Dmy:
					{
						string day = Options.DateTime.GetDay(true);
						string month = Options.DateTime.GetMonth(true);
						string year = Options.DateTime.GetYear(false);
						Options.DateTime._mFormatDate = ((day.Length == 1) ? "" : (day + ((month.Length == 1) ? "" : month) + year));
						if (Options.DateTime._mFormatDate.Trim() == string.Empty)
						{
							Options.DateTime._mFormatDate = "dd/MM/yyyy";
						}
						mFormatDate = Options.DateTime._mFormatDate;
						break;
					}
					case Options.FormatType.Mdy:
					{
						string day = Options.DateTime.GetDay(true);
						string month = Options.DateTime.GetMonth(true);
						string year = Options.DateTime.GetYear(false);
						Options.DateTime._mFormatDate = ((month.Length == 1) ? "" : (month + ((day.Length == 1) ? "" : day) + year));
						if (Options.DateTime._mFormatDate.Trim() == string.Empty)
						{
							Options.DateTime._mFormatDate = "MM/dd/yyyy";
						}
						mFormatDate = Options.DateTime._mFormatDate;
						break;
					}
					case Options.FormatType.Ymd:
					{
						string day = Options.DateTime.GetDay(false);
						string month = Options.DateTime.GetMonth(true);
						string year = Options.DateTime.GetYear(true);
						Options.DateTime._mFormatDate = ((year.Length == 1) ? "" : (year + ((month.Length == 1) ? "" : month) + day));
						if (Options.DateTime._mFormatDate.Trim() == string.Empty)
						{
							Options.DateTime._mFormatDate = "yyyy/MM/dd";
						}
						mFormatDate = Options.DateTime._mFormatDate;
						break;
					}
					default:
						mFormatDate = Options.DateTime._mFormatDate;
						break;
					}
					return mFormatDate;
				}
				set
				{
					Options.DateTime._mDateFormatType = Options.FormatType.Custom;
					Options.DateTime._mFormatDate = value;
				}
			}
			public static string FormatString
			{
				get
				{
					return "{0:" + Options.DateTime.Format + "}";
				}
			}
			public static string Saparator
			{
				get
				{
					return Options.DateTime._mDateSaparator;
				}
				set
				{
					Options.DateTime._mDateSaparator = value;
				}
			}
			public static int DayLength
			{
				get
				{
					return Options.DateTime._mDayLength;
				}
				set
				{
					Options.DateTime._mDayLength = value;
				}
			}
			public static int MonthLength
			{
				get
				{
					return Options.DateTime._mMonthLength;
				}
				set
				{
					Options.DateTime._mMonthLength = value;
				}
			}
			public static int YearLength
			{
				get
				{
					return Options.DateTime._mYearLength;
				}
				set
				{
					Options.DateTime._mYearLength = value;
				}
			}
			private static string GetDay(bool dateSaparator)
			{
				string text = "";
				for (int i = 0; i < Options.DateTime._mDayLength; i++)
				{
					text += "d";
				}
				if (dateSaparator)
				{
					text += Options.DateTime._mDateSaparator;
				}
				return text;
			}
			private static string GetMonth(bool dateSaparator)
			{
				string text = "";
				for (int i = 0; i < Options.DateTime._mMonthLength; i++)
				{
					text += "M";
				}
				if (dateSaparator)
				{
					text += Options.DateTime._mDateSaparator;
				}
				return text;
			}
			private static string GetYear(bool dateSaparator)
			{
				string text = "";
				for (int i = 0; i < Options.DateTime._mYearLength; i++)
				{
					text += "y";
				}
				if (dateSaparator)
				{
					text += Options.DateTime._mDateSaparator;
				}
				return text;
			}
		}
		private static XProgressForm _progressForm;
        private static XLoadingForm _LoadingForm;
		private static WaitDialogForm _mDlg;
		private static string _mFTitle;
		private static string _mCaption;
		public static int TypeSoft
		{
			get;
			set;
		}
		public static XProgressForm FormProcess
		{
			get
			{
				return Options._progressForm;
			}
			set
			{
				Options._progressForm = value;
			}
		}
		public static string SoftId
		{
			get;
			set;
		}
		public static string Caption
		{
			get
			{
				return Options._mCaption;
			}
			set
			{
				Options._mCaption = value;
			}
		}
		public static string Title
		{
			get
			{
				return Options._mFTitle;
			}
			set
			{
				Options._mFTitle = value;
			}
		}
		static Options()
		{
			Options._progressForm = new XProgressForm();
            //Options._LoadingForm = new XLoadingForm();
			Options._mFTitle = "Vui lòng đợi trong giây lát...";
			Options._mCaption = "Đang nạp dữ liệu ...";
			Options.SoftId = "QLK";
			Options.TypeSoft = 0;
		}
		public static void CreateWaitDialog()
		{
			Options.CreateWaitDialog(Options.Caption);
		}
		public static void CreateWaitDialog(string fCaption)
		{
			Options.CreateWaitDialog(fCaption, Options.Title);
		}
		public static void CreateWaitDialog(string fCaption, string fTitle)
		{
			Options.Title = fTitle;
			if (Options._mDlg == null)
			{
				Options._mDlg = new WaitDialogForm(fCaption, fTitle);
			}
			Options._mDlg.AllowFormSkin = true;
		}
		public static void SetWaitDialogCaption()
		{
			Options.SetWaitDialogCaption(Options.Caption);
		}
		public static void SetWaitDialogCaption(string fCaption)
		{
			Options.Caption = fCaption;
			if (Options._mDlg != null)
			{
				Options._mDlg.Visible = true;
				Options._mDlg.Caption = fCaption;
			}
			else
			{
				Options.CreateWaitDialog();
			}
		}
		public static void Show(string fCaption)
		{
			Options.SetWaitDialogCaption(fCaption);
		}
		public static void Show()
		{
			Options.SetWaitDialogCaption();
		}
		public static void CloseDialog()
		{
			if (Options._mDlg != null)
			{
				Options._mDlg.FormClosing += new FormClosingEventHandler(Options.DlgFormClosing);
				Options._mDlg.Close();
			}
		}
		public static void HideDialog()
		{
			if (Options._mDlg != null)
			{
				Options._mDlg.Hide();
			}
		}
		public static void Close()
		{
			Options.CloseDialog();
		}
		private static void DlgFormClosing(object sender, FormClosingEventArgs e)
		{
			Options._mDlg = null;
		}
		~Options()
		{
			if (Options._mDlg != null)
			{
				Options._mDlg.FormClosing += new FormClosingEventHandler(Options.DlgFormClosing);
				Options._mDlg.Close();
			}
		}

        public static XLoadingForm FormLoading
        {
            get
            {
                return _LoadingForm;
            }
            set
            {
                _LoadingForm = value;
            }
        }

	}
}
